namespace KPIS.GERP.Models.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class update0146 : DbMigration
    {
        public override void Up()
        {
            RenameTable(name: "dbo.SchedulerReports", newName: "sys_scheduler_report");
            DropForeignKey("dbo.SchedulerReportCmds", "CmdId", "dbo.hrm_ps_commands");
            DropForeignKey("dbo.SchedulerReportCmds", "CmdDtlId", "dbo.hrm_ps_command_dtls");
            DropForeignKey("dbo.SchedulerReportCmds", "SchRepId", "dbo.SchedulerReports");
            DropIndex("dbo.SchedulerReportCmds", new[] { "CmdId" });
            DropIndex("dbo.SchedulerReportCmds", new[] { "CmdDtlId" });
            DropIndex("dbo.SchedulerReportCmds", new[] { "SchRepId" });
            RenameColumn(table: "dbo.sys_scheduler_report", name: "SchRepId", newName: "sch_rep_seq");
            RenameColumn(table: "dbo.sys_scheduler_report", name: "ErrorMessage", newName: "error_message");
            RenameColumn(table: "dbo.sys_scheduler_report", name: "AmountCommandToExecute", newName: "amount_command_to_execute");
            RenameColumn(table: "dbo.sys_scheduler_report", name: "CmdDtlIdExecuteError", newName: "cmd_dtl_seq_execute_error");
            RenameColumn(table: "dbo.sys_scheduler_report", name: "ErrorWhen", newName: "error_when");
            RenameColumn(table: "dbo.sys_scheduler_report", name: "StartWhen", newName: "start_when");
            RenameColumn(table: "dbo.sys_scheduler_report", name: "StopWhen", newName: "stop_when");
            RenameColumn(table: "dbo.sys_scheduler_report", name: "ExecuteCompleted", newName: "execute_completed");
            CreateTable(
                "dbo.sys_scheduler_report_cmddtl",
                c => new
                    {
                        sch_rep_cmddtl_seq = c.Int(nullable: false, identity: true),
                        sch_rep_seq = c.Int(),
                        cmd_seq = c.Int(),
                        cmd_dtl_seq = c.Int(),
                    })
                .PrimaryKey(t => t.sch_rep_cmddtl_seq)
                .ForeignKey("dbo.hrm_ps_commands", t => t.cmd_seq)
                .ForeignKey("dbo.hrm_ps_command_dtls", t => t.cmd_dtl_seq)
                .ForeignKey("dbo.sys_scheduler_report", t => t.sch_rep_seq)
                .Index(t => t.cmd_seq)
                .Index(t => t.cmd_dtl_seq)
                .Index(t => t.sch_rep_seq);
            
            DropColumn("dbo.sys_scheduler_report", "AmountCommandExecutePass");
            DropColumn("dbo.sys_scheduler_report", "IsStartManually");
            DropTable("dbo.SchedulerReportCmds");
        }
        
        public override void Down()
        {
            CreateTable(
                "dbo.SchedulerReportCmds",
                c => new
                    {
                        SchRepCmdId = c.Int(nullable: false, identity: true),
                        SchRepId = c.Int(),
                        CmdId = c.Int(),
                        CmdDtlId = c.Int(),
                    })
                .PrimaryKey(t => t.SchRepCmdId);
            
            AddColumn("dbo.sys_scheduler_report", "IsStartManually", c => c.Boolean(nullable: false));
            AddColumn("dbo.sys_scheduler_report", "AmountCommandExecutePass", c => c.Int());
            DropIndex("dbo.sys_scheduler_report_cmddtl", new[] { "sch_rep_seq" });
            DropIndex("dbo.sys_scheduler_report_cmddtl", new[] { "cmd_dtl_seq" });
            DropIndex("dbo.sys_scheduler_report_cmddtl", new[] { "cmd_seq" });
            DropForeignKey("dbo.sys_scheduler_report_cmddtl", "sch_rep_seq", "dbo.sys_scheduler_report");
            DropForeignKey("dbo.sys_scheduler_report_cmddtl", "cmd_dtl_seq", "dbo.hrm_ps_command_dtls");
            DropForeignKey("dbo.sys_scheduler_report_cmddtl", "cmd_seq", "dbo.hrm_ps_commands");
            DropTable("dbo.sys_scheduler_report_cmddtl");
            RenameColumn(table: "dbo.sys_scheduler_report", name: "execute_completed", newName: "ExecuteCompleted");
            RenameColumn(table: "dbo.sys_scheduler_report", name: "stop_when", newName: "StopWhen");
            RenameColumn(table: "dbo.sys_scheduler_report", name: "start_when", newName: "StartWhen");
            RenameColumn(table: "dbo.sys_scheduler_report", name: "error_when", newName: "ErrorWhen");
            RenameColumn(table: "dbo.sys_scheduler_report", name: "cmd_dtl_seq_execute_error", newName: "CmdDtlIdExecuteError");
            RenameColumn(table: "dbo.sys_scheduler_report", name: "amount_command_to_execute", newName: "AmountCommandToExecute");
            RenameColumn(table: "dbo.sys_scheduler_report", name: "error_message", newName: "ErrorMessage");
            RenameColumn(table: "dbo.sys_scheduler_report", name: "sch_rep_seq", newName: "SchRepId");
            CreateIndex("dbo.SchedulerReportCmds", "SchRepId");
            CreateIndex("dbo.SchedulerReportCmds", "CmdDtlId");
            CreateIndex("dbo.SchedulerReportCmds", "CmdId");
            AddForeignKey("dbo.SchedulerReportCmds", "SchRepId", "dbo.SchedulerReports", "SchRepId");
            AddForeignKey("dbo.SchedulerReportCmds", "CmdDtlId", "dbo.hrm_ps_command_dtls", "cmd_dtls_seq");
            AddForeignKey("dbo.SchedulerReportCmds", "CmdId", "dbo.hrm_ps_commands", "cmd_seq");
            RenameTable(name: "dbo.sys_scheduler_report", newName: "SchedulerReports");
        }
    }
}
